package com.dubbo.server.utils;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;

import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.teaopenapi.models.Config;


//阿里云短信发送工具类
public class SedSms {
    public static Boolean sendMsg(String phone, String templateCode, String code) {
        try {
            Config config = new Config()
             //AccessKey ID
             .setAccessKeyId("LTAI5tSoLnXEDhrwmnJjwk7n")
             //AccessKey Secret
             .setAccessKeySecret("MSXsvCZyhEGNHbKK1pz5sSOt46HlRK");
            config.endpoint = "dysmsapi.aliyuncs.com";
            Client client = new Client(config);
            SendSmsRequest sendSmsRequest = new SendSmsRequest()
             .setPhoneNumbers(phone)
             .setSignName("杭州黑马健康")
             .setTemplateCode(templateCode)
             .setTemplateParam("{\"code\":\"" + code + "\"}");
            SendSmsResponse sendSmsResponse = client.sendSms(sendSmsRequest);
            if (sendSmsResponse.getBody().getCode().equalsIgnoreCase("ok")) {
                return true;
            }
        } catch (Exception e) {
            return false;
        }
        return false;
    }
}
